<?php


namespace app\common\model;


use think\Model;

class PrivateChatSessionModel extends Model
{
    const DEVICE_TYPE = [
        0 => '浏览器',
        1 => '苹果',
        2 => '安卓',
    ];

    public static function getDeviceTextAttr($value, $data)
    {
        return isset(self::DEVICE_TYPE[$data['device']]) ? self::DEVICE_TYPE[$data['device']] : '--';
    }

    public function user()
    {
        return $this->hasOne(UserModel::class, 'id', 'user_id');
    }

    public function anchor()
    {
        return $this->hasOne(UserModel::class, 'id', 'anchor_id');
    }

    public function admin()
    {
        return $this->hasOne(AdminModel::class, 'id', 'admin_id');
    }

    public function chatHistory()
    {
        return $this->hasOne(PrivateChatHistoryModel::class, 'id', 'private_chat_history_id');
    }

}